<#import "/manage/tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="会员管理">
<#-------------------------------------------------------搜索表单start------------------------------------------------------->
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li>
            <div class="control-group span8">
                <label class="control-label">帐号：</label>

                <div class="controls">
                    <input type="text" name="account" value="${e.account!""}">
                </div>
            </div>
            <div class="control-group span8">
                <label class="control-label">昵称：</label>

                <div class="controls">
                    <input type="text" name="nickname" value="${e.nickname!""}">
                </div>
            </div>
            <div class="control-group span8">
                <label class="control-label">状态：</label>

                <div class="controls">
                    <select name="freeze" class="input-normal">
                        <option value="">全部</option>
                        <option value="y">已冻结</option>
                        <option value="n">未冻结</option>
                    </select>
                </div>
            </div>
        </li>
        <li>
            <div class="control-group span8">
                <label class="control-label">会员等级：</label>

                <div class="controls">
                    <select name="rank" class="input-normal">
                        <option value="">全部</option>
                        <option value="R1">普通会员</option>
                        <option value="R2">铜牌会员</option>
                        <option value="R3">银牌会员</option>
                        <option value="R4">金牌会员</option>
                        <option value="R5">钻石会员</option>
                    </select>
                </div>
            </div>
            <div class="control-group span10">
                <label class="control-label">注册日期：</label>

                <div class="controls bui-form-group" data-rules="{dateRange : true}">
                    <input name="startDate" class="input-small calendar" type="text">
                    <label>&nbsp;-&nbsp;</label>
                    <input name="endtDate" class="input-small calendar" type="text">
                </div>
            </div>
            <div class="form-actions span6">
                <button type="submit" class="button  button-primary">
                    查询
                </button>
            </div>
        </li>

    </ul>
</form>
<#-------------------------------------------------------搜索表单 end-------------------------------------------------------->
<#-------------------------------------------------------编辑表单start------------------------------------------------------->
<div id="editContent" style="display: none">
    <form action="${basepath}/manage/account/updateJson" id="editForm" class="form-horizontal" method="post">
        <input type="hidden" class="input-normal control-text" name="id"/>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">昵称：</label>
                <div class="controls" >
                    <input type="text" class="input-normal input-text" name="nickname"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">账号：</label>

                <div class="controls">
                    <input type="text" class="input-normal input-text" name="account"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">是否冻结：</label>

                <div class="controls">
                    <select class="input-normal input-text" name="freeze">
                        <option value="y">是</option>
                        <option value="n">否</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <div class="controls">
                    <label class="control-label">冻结时间范围：</label>
                    <input name="startDate" class="input-small calendar" type="text" id="d4311"/>
                    <label>&nbsp;-&nbsp;</label>
                    <input name="endDate" class="input-small calendar" type="text" id="d4312"/>
                </div>
            </div>
        </div>
    </form>
</div>
<#-------------------------------------------------------编辑表单 end-------------------------------------------------------->
<div id="grid"></div>

<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '登陆方式', dataIndex: 'accountType', width: 100},
                {title: '帐号', dataIndex: 'account', width: 100},
                {title: '昵称', dataIndex: 'nickname', width: 100},
                {title: '会员等级', dataIndex: 'rankName', width: 100},
                {title: '邮箱', dataIndex: 'email', width: 100},
                {title: '注册日期', dataIndex: 'regeistDate', width: 100},
                {title: '最后登录时间', dataIndex: 'lastLoginTime', width: 100},
                {title: '最后登录IP', dataIndex: 'lastLoginIp', width: 100},
                {
                    title: '是否冻结', dataIndex: 'freeze', width: 80, renderer: function (data) {
                    if (data == "y") {
                        return '<img src="${basepath}/resource/images/login.gif">';
                    } else {
                        return '';
                    }
                }
                },
                {
                    title: '操作', dataIndex: 'id', width: 80, renderer: function (value) {

                    <#if checkPrivilege("/manage/user/edit")>
                        return '<a href="javascript:edit(' + value + ')">冻结</a>';
                    <#else>
                        return "";
                    </#if>
                }
                }
            ];

    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();
    var params = form.serializeToObject();
    params.length = '10';
    form.on('beforesubmit', function (ev) {
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    var store = new Store({
                url: 'loadData',
                autoLoad: true, //自动加载数据
                params: params,
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格

                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });

    grid.on("aftershow", function (e) {
        //万恶的json导致菜单栏高度问题
        $(".dl-second-nav").css("height", $(".dl-inner-tab").css("height"));
    });
    grid.render();


    /**
     * 删除选中的记录
     */
    function delFunction() {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/manage/account/deletesJson",
            dataType: "json",
            data: {
                ids: ids
            },
            success: function (data) {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });

    }

    /*----------------------------------------------编辑表单处理 begin------------------------------------*/
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    });
    editForm.render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '冻结用户',
        width: 500,
        height: 320,
        contentId: 'editContent',
        success: function () {
            editForm.ajaxSubmit();
        }
    });
    //编辑按钮事件
    function edit(id) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "${basepath}/manage/account/toEditJson",
            data: {id: id},
            success: function (data) {
                var form = $("#editForm")[0];
                BUI.FormHelper.setFields(form, data.data);
                editDialog.show();
            }
        });
    }
    /*----------------------------------------------编辑表单处理 end------------------------------------*/

</script>


</@page.pageBase>